<?php

namespace app\admin\controller;

use app\common\model\Admin;
use houdunwang\crypt\Crypt;
use think\Controller;

class Login extends Controller {
    // 用户登陆
    public function login() {
        /*
        # 加密
        echo Crypt::encrypt('admin');
        echo '<hr>';
        # 解密
        echo Crypt::decrypt('gKjd5W7T3zzGPZJBiKMv5Q==');
        */
        /*
         * 测试连接数据库
         * $data = db('admin')->find(1);
         * dump($data);
         */

        if(request()->isPost()){
            $res = (new Admin())->login(input('post.'));
            if($res['valid']){
                // 说明登录成功
                $this->success($res['msg'],'admin/entry/index');
            }else{
                // 说明登录失败
                $this->error($res['msg']);exit;
            }
        }


        return $this->fetch();
    }

    // 退出
    public function logout() {
        session(null);
        return redirect('login');
    }

}
